package ventanas;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import controladores.ControladorBusquedaMedicos;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JLabel;
import negocio.Medico;
import javax.swing.JScrollPane;

public class VentanaBusquedaMedicos extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private final JTextField txtBuscarMedico = new JTextField();
	private final JButton btnBuscarMedico = new JButton("Buscar M\u00E9dico");
	private final JList<Medico> lista = new JList<Medico>();
	private final JButton btnC = new JButton("C");
	private final JButton btnNuevoMedico = new JButton("Nuevo M\u00E9dico");
	private final JLabel lblMedicos = new JLabel("M\u00E9dicos");
	private ControladorBusquedaMedicos controlador;
	private final JScrollPane scrollPane = new JScrollPane();

	public VentanaBusquedaMedicos() {
		setTitle("B\u00FAsqueda de M\u00E9dico");
		this.controlador = new ControladorBusquedaMedicos(this);
		initGUI();
		agregarlisteners();
	}
	
	private void initGUI() {
		setBounds(100, 100, 421, 340);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new FormLayout(new ColumnSpec[] {
				ColumnSpec.decode("max(175dlu;default):grow"),
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("max(84dlu;default)"),},
			new RowSpec[] {
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("max(97dlu;default):grow"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("max(44dlu;default)"),}));
		
		txtBuscarMedico.setColumns(10);
		contentPane.add(lblMedicos, "1, 1, center, center");
		contentPane.add(txtBuscarMedico, "1, 3, fill, center");
		contentPane.add(btnBuscarMedico, "3, 3");
		contentPane.add(btnC, "3, 5");
		
		contentPane.add(scrollPane, "1, 7, fill, fill");
		contentPane.add(btnNuevoMedico, "3, 7, default, top");
		this.setVisible(true);
		this.setLocationRelativeTo(null);
		this.pack();
	}
	
	private void agregarlisteners(){
		btnBuscarMedico.addActionListener(controlador);
		btnC.addActionListener(controlador);
		btnNuevoMedico.addActionListener(controlador);
		scrollPane.setViewportView(lista);
		lista.addMouseListener(controlador);
	}
	
	//getters y setters
	public JTextField gettxtBuscarMedico() {
		return txtBuscarMedico;
	}
	
	public JButton getbtnBuscarMedico() {
		return btnBuscarMedico;
	}
	
	public JList<Medico> getLista() {
		return lista;
	}
	
	public JButton getBtnC() {
		return btnC;
	}
	
	public JButton getbtnNuevoMedico() {
		return btnNuevoMedico;
	}
}
